<template>
  <div class="login">
    <!-- tain添加一个登录表单 -->
    <el-form :rules="rules" class="myform" :model="form">
      <h3 class="title">iHRM 后台管理系统</h3>
      <!-- 表单区域 -->
      <el-form-item prop="mobile">
        <el-input prefix-icon="el-icon-user-solid" v-model="form.mobile"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" show-password prefix-icon="el-icon-lock" v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="mybtn">登录</el-button>
      </el-form-item>
      <el-form-item>
        <div class="txt">还没有账号？立即注册</div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
name:'login',
data () {
  return{
    form:{
      mobile:'',
      password:''
    },
    // 校验规则
    rules:{
      mobile:[
        // 必填项
        {required:true,message:'请输入手机号','trigger':'blur'},
        // 添加手机号的校验
        {
          validator:(rule,value,callback) => {
            // 校验手机号的合法
            // 定义一个手机号的正则
            const reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
            // 用正则去匹配value
            const bool = reg.test(value)
            // 返回true 说明通过 否则 提示错误
            bool ? callback() : callback(new Error('手机号不合法'))
          },
          trigger:'blur'
        }
      ],
      password:[
        // 必填项
        {required:true,message:'请输入密码','trigger':'blur'}
      ],
    }
  }
}
}
</script>

<style lang="scss">
.login {
  height: 100%;
  background-image: url('../../assets/common/login.jpg');
  background-position: center;
  position: relative;
  .myform {
    width: 450px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    .title{
      color: #fff;
      font-size: 50px;
      font-weight: 400;
    }
    input.el-input__inner{
      height: 50px;
      background: #d4e5ff;
      color: #68b0fe;
    }
    .mybtn{
      width: 100%;
      height: 50px;
      background-color: #407ffe;
      border: none;
      color: #fff;
      font-size: 20px;
    }
    .txt{
      text-align: center;
      color: #fff;
    }
    .el-form-item__error{
      color: #fff;
    }
  }
}
</style>